using ASP;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Member_EditProducts : Member, IRequiresSessionState
{
	protected Literal TxtOrderFormNum;
	protected TextBox TxtPuint;
	protected RadioButtonList ProductStandard;
	protected TextBox ProductStock;
	protected RequiredFieldValidator rfv3;
	protected RangeValidator rav_2;
	protected ScriptManager ScriptManager1;
	protected Shop_UserControls_HowaveProvinceCity ProvinceCity;
	protected RadioButtonList NeedInvoice;
	protected TextBox TxtTaxRate;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected RangeValidator RangeValidator1;
	protected RadioButtonList Guarantee;
	protected CheckBoxList CheckBoxList_OnlinePayType;
	protected RadioButtonList Radio_DeliverPayType;
	protected RadioButtonList CheckBoxList_DeliverType;
	protected DropDownList ValidDay;
	protected RadioButtonList ProductPublishTime;
	protected TextBox PublishStartDay;
	protected DropDownList PublishStartHour;
	protected DropDownList PublishStartMin;
	protected CheckBox AutoPostBack;
	protected CheckBox IsElite;
	protected Button Button3;
	private Shop_PayType _shop_paytype = null;
	private Shop_DeliverType _shop_delivertype = null;
	private int _productStock = 0;
	private Shop_Product _shop_product = null;
	private string tag = "";
	private string _txtPuint = "";
	private int _taxRate = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Shop_PayType shop_paytype
	{
		get
		{
			Shop_PayType shop_paytype;
			if (this._shop_paytype == null)
			{
				this._shop_paytype = new Shop_PayType(this.conn);
				shop_paytype = this._shop_paytype;
			}
			else
			{
				shop_paytype = this._shop_paytype;
			}
			return shop_paytype;
		}
	}
	protected Shop_DeliverType shop_delivertype
	{
		get
		{
			Shop_DeliverType shop_delivertype;
			if (this._shop_delivertype == null)
			{
				this._shop_delivertype = new Shop_DeliverType(this.conn);
				shop_delivertype = this._shop_delivertype;
			}
			else
			{
				shop_delivertype = this._shop_delivertype;
			}
			return shop_delivertype;
		}
	}
	protected int productStock
	{
		get
		{
			int productStock;
			try
			{
				this._productStock = int.Parse(this.ProductStock.Text);
				productStock = this._productStock;
			}
			catch
			{
				productStock = this._productStock;
			}
			return productStock;
		}
	}
	protected Shop_Product shop_product
	{
		get
		{
			Shop_Product shop_product;
			if (this._shop_product == null)
			{
				this._shop_product = new Shop_Product(this.conn);
				shop_product = this._shop_product;
			}
			else
			{
				shop_product = this._shop_product;
			}
			return shop_product;
		}
	}
	protected string txtPuint
	{
		get
		{
			string txtPuint;
			if (this.TxtPuint.Text != "")
			{
				this._txtPuint = this.TxtPuint.Text;
				txtPuint = this._txtPuint;
			}
			else
			{
				txtPuint = this._txtPuint;
			}
			return txtPuint;
		}
	}
	protected int taxRate
	{
		get
		{
			int taxRate;
			try
			{
				this._taxRate = int.Parse(this.TxtTaxRate.Text);
				taxRate = this._taxRate;
			}
			catch
			{
				taxRate = this._taxRate;
			}
			return taxRate;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.tag = base.Request.QueryString["tag"];
		if (this.tag != null)
		{
			if (this.tag == "EnableSale")
			{
				if (this.ProductPublishTime.Items.Count == 3)
				{
					this.ProductPublishTime.Items.Remove(this.ProductPublishTime.Items[2]);
				}
			}
		}
		if (!base.IsPostBack)
		{
			this.PublishStartDay.Attributes.Add("onclick", "SelectDate(" + this.PublishStartDay.UniqueID + ",'yyyy-MM-dd');");
			this.loadOnlinePayType();
			this.loaddelivertype();
			this.loadvailyday();
		}
	}
	private void loadOnlinePayType()
	{
		this.CheckBoxList_OnlinePayType.Items.Clear();
		DataTable payTypeByUserID = this.shop_paytype.GetPayTypeByUserID(base.user.UserID);
		int num = 0;
		foreach (DataRow dataRow in payTypeByUserID.Rows)
		{
			ListItem listItem = new ListItem();
			listItem.Text = dataRow["TypeName"].ToString();
			listItem.Value = dataRow["TypeID"].ToString();
			this.CheckBoxList_OnlinePayType.Items.Add(listItem);
			this.CheckBoxList_OnlinePayType.Items[num].Selected = true;
			num++;
		}
	}
	private void loaddelivertype()
	{
		this.CheckBoxList_DeliverType.Items.Clear();
		DataTable deliverTypeByUserID = this.shop_delivertype.GetDeliverTypeByUserID(base.user.UserID);
		foreach (DataRow dataRow in deliverTypeByUserID.Rows)
		{
			ListItem listItem = new ListItem();
			listItem.Text = dataRow["TypeName"].ToString();
			listItem.Value = dataRow["TypeID"].ToString();
			this.CheckBoxList_DeliverType.Items.Add(listItem);
			this.CheckBoxList_DeliverType.Items[0].Selected = true;
		}
	}
	private void loadvailyday()
	{
		string text = base.shopconfig["SaleDay"].ToString();
		if (text.Contains("|"))
		{
			string[] array = text.Split(new char[]
			{
				'|'
			});
			for (int i = 0; i < array.Length; i++)
			{
				this.ValidDay.Items.Add(array[i]);
			}
		}
	}
	protected void Button3_Click(object sender, EventArgs e)
	{
		string text = base.Request.QueryString["productIDS"].ToString();
		string[] array = text.Split(new char[]
		{
			','
		});
		int[] array2 = new int[array.Length];
		for (int i = 0; i < array2.Length; i++)
		{
			array2[i] = int.Parse(array[i]);
		}
		string text2 = base.Request.Params.Get("cbselect");
		if (text2 == null || string.IsNullOrEmpty(text2))
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('请选择需要修改的选项!');</script>");
		}
		else
		{
			string text3 = "0";
			string[] array3 = text2.Split(new char[]
			{
				','
			});
			string[] array4 = new string[array3.Length];
			string[] array5 = new string[array3.Length];
			string[] array6 = new string[array3.Length];
			ArrayList arrayList = new ArrayList();
			int num = array3.Length;
			for (int i = 0; i < num; i++)
			{
				string text4 = array3[i];
				switch (text4)
				{
				case "0":
					array4[i] = "PUnit";
					array5[i] = this.TxtPuint.Text;
					arrayList.Add(this.TxtPuint.Text);
					array6[i] = "string";
					break;
				case "1":
					array4[i] = "ProductStandard";
					array5[i] = this.ProductStandard.SelectedValue;
					arrayList.Add(this.ProductStandard.SelectedValue);
					array6[i] = "string";
					break;
				case "2":
					array4[i] = "Stocks";
					array5[i] = this.ProductStock.Text;
					arrayList.Add(this.ProductStock.Text);
					array6[i] = "int";
					break;
				case "3":
					array4[i] = "Province,City";
					array5[i] = this.ProvinceCity.SelectedProvince + "," + this.ProvinceCity.SelectedCity;
					array6[i] = "string";
					break;
				case "4":
					array4[i] = "NeedInvoice";
					array5[i] = this.NeedInvoice.SelectedValue;
					array6[i] = "bit";
					break;
				case "5":
					array4[i] = "TaxRate";
					array5[i] = this.TxtTaxRate.Text;
					array6[i] = "int";
					break;
				case "6":
					array4[i] = "Guarantee";
					array5[i] = this.Guarantee.SelectedValue;
					array6[i] = "bit";
					break;
				case "8":
				{
					array4[i] = "PayType";
					string text5 = "";
					int count = this.CheckBoxList_OnlinePayType.Items.Count;
					for (int j = 0; j < count; j++)
					{
						if (this.CheckBoxList_OnlinePayType.Items[j].Selected)
						{
							if (j < count - 1)
							{
								text5 = text5 + this.CheckBoxList_OnlinePayType.Items[j].Value + ",";
							}
							else
							{
								text5 += this.CheckBoxList_OnlinePayType.Items[j].Value;
							}
						}
					}
					array5[i] = text5;
					array6[i] = "string";
					break;
				}
				case "9":
					if (this.Radio_DeliverPayType.SelectedValue == "1")
					{
						array4[i] = "DeliverType,DeliverPayType";
						array5[i] = this.CheckBoxList_DeliverType.SelectedValue + ",1";
					}
					else
					{
						array4[i] = "DeliverPayType,DeliverPayType";
						array5[i] = "0,0";
					}
					array6[i] = "int";
					break;
				case "10":
					array4[i] = "ValidDay";
					array5[i] = this.ValidDay.SelectedValue;
					text3 = this.ValidDay.SelectedValue;
					array6[i] = "int";
					break;
				case "11":
				{
					array4[i] = "BeginDate,Enddate";
					DateTime dateTime = default(DateTime);
					DateTime dateTime2 = default(DateTime);
					if (this.ProductPublishTime.SelectedValue == "0")
					{
						dateTime = DateTime.Now.AddDays(1000.0);
						dateTime2 = Convert.ToDateTime("1980-1-1");
					}
					else
					{
						if (this.ProductPublishTime.SelectedValue == "1")
						{
							dateTime = DateTime.Now;
							if (text3 == "0")
							{
								dateTime2 = Convert.ToDateTime("1980-1-1");
							}
							else
							{
								dateTime2 = DateTime.Now.AddDays(double.Parse(text3));
							}
						}
						else
						{
							dateTime = DateTime.Parse(string.Concat(new string[]
							{
								this.PublishStartDay.Text,
								" ",
								this.PublishStartHour.SelectedValue,
								":",
								this.PublishStartMin.SelectedValue,
								":20"
							}));
							if (text3 == "0")
							{
								dateTime2 = Convert.ToDateTime("1980-1-1");
							}
							else
							{
								dateTime2 = DateTime.Parse(string.Concat(new string[]
								{
									this.PublishStartDay.Text,
									" ",
									this.PublishStartHour.SelectedValue,
									":",
									this.PublishStartMin.SelectedValue,
									":20"
								})).AddDays(double.Parse(text3));
							}
						}
					}
					array5[i] = dateTime.ToString() + "," + dateTime2.ToString();
					array6[i] = "DateTime";
					break;
				}
				case "12":
				{
					string text6 = "0";
					array4[i] = "AutoPostBack";
					if (this.AutoPostBack.Checked)
					{
						text6 = "1";
					}
					array5[i] = text6;
					array6[i] = "bool";
					break;
				}
				case "13":
				{
					array4[i] = "IsElite";
					string text7 = "0";
					if (this.IsElite.Checked)
					{
						text7 = "1";
					}
					array5[i] = text7;
					array6[i] = "bool";
					break;
				}
				}
			}
			int num3 = this.shop_product.new_updateproducts(array2, array4, array5, array6);
			if (num3 == array2.Length)
			{
				if (this.tag == "EnableSale")
				{
					this.WriteSuccessMsg("恭喜你", "成功修改所选择的商品", "Shop_ProductInStock.aspx");
				}
				else
				{
					this.WriteSuccessMsg("恭喜你", "成功修改所选择的商品", "Shop_ProductSale.aspx");
				}
			}
			else
			{
				this.WriteErrMsg("失败了", "批量修改出错,请重新输入", "EditProducts.aspx");
			}
		}
	}
	private bool checkInput()
	{
		return false;
	}
}
